package org.jader.bolao.gui.swing;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

public class PDFFileChooser extends JFileChooser {
	private static final long serialVersionUID = 1L;
	
	public PDFFileChooser() {
		super();
		this.setFileFilter(new FileFilter() {
			@Override
			public boolean accept(File arg0) {
				if (arg0.isDirectory()) return true;
				return arg0.getName().endsWith("pdf");
			}

			@Override
			public String getDescription() {
				return "Arquivos PDF (*.pdf)";
			}
		});
	}

	@Override
	public File getSelectedFile() {
		File saveFile = super.getSelectedFile();
		String name = saveFile.getName();
		if (!name.endsWith(".pdf")) {
			saveFile = new File(saveFile.getParentFile(), name+".pdf");
		}
		return saveFile;
	}
}
